const path = require('path')
const fs = require('fs')
const config = require('../config/config')
module.exports = (app) => {
  const routerPath = path.join(path.dirname(__dirname), 'router')
  const routerFileList = fs.readdirSync(routerPath)
  // console.log();
  routerFileList.forEach(file => {
    const fileModule = require(path.join(routerPath, file))
    const prefix = `/${file.replace('.js', '').replace(/\./g, '/')}`
    fileModule['prefix'](prefix)
    // console.log(fileModule.noAuthList);
    // console.log(fileModule,fileModule.noAuthList);
    if (fileModule.noAuthList) {
    // console.log(fileModule.noAuthList.map(item => prefix + item));

      config.jwt.anonymPaths.push(...fileModule.noAuthList.map(item => prefix + item))
    }
    app.use(fileModule['routes'](), fileModule['allowedMethods']())
  })
  console.log('放行的接口:', config.jwt.anonymPaths);

  // router
  // app.use(index.router(), index.allowedMethods())
  // app.use(users.router(), users.allowedMethods())

}